<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;

class NaxinController extends CommonController {
    public function index(){
    	clickNum();
    	$this->display();
	}

	//纳新表单处理
	public function handle(){
        $url = uploadImage();
        if($url == -1){
            $this->ajaxReturn('error,upfile image');
        }
        $data=array(
            'image_url' => $url,
            'name'=>$_POST['name'],
            'sex'=>$_POST['sex'],
            'birthday'=>$_POST['birthday'],
            'political'=>$_POST['political'],
            'nation'=>$_POST['nation'],
            'origin'=>$_POST['origin'],
            'school_id'=>$_POST['school'],
            'major_id'=>$_POST['specialty'],
            'yidong'=>$_POST['yidong'],
            'liantong'=>$_POST['liantong'],
            'qq'=>$_POST['qq'],
            'hostel'=>$_POST['hostel'],
            'is_move'=>$_POST['is_move'],
            'strength'=>$_POST['strength'],
            'practice'=>$_POST['practice'],
            'encourage'=>$_POST['encourage'],
            'evaluation'=>$_POST['evaluation'],
        );
        if(!($user_id = M('user')->add($data))){
            $this->ajaxReturn('error,insert into user');
        }
        $data = array(
            'user_id' => $user_id,
            'department_id' => $_POST['first_dep'],
            'wish'  => 1,
        );
        if(!(M('user_department')->add($data))){
            $this->ajaxReturn('error,insert into user_department,first_dep');
        }
        $data = array(
            'user_id' => $user_id,
            'department_id' => $_POST['second_dep'],
            'wish'  => 2,
        );
        if(!(M('user_department')->add($data))){
            $this->ajaxReturn('error,insert into user_department,second_dep');
        }
        $this->success('报名成功');
	}
}